# -*- coding: utf-8 -*-
"""
-------------------------------------------------
File Name： alarm_format
Description :
Author : 'li'
date： 1/15/2024
-------------------------------------------------
Change Activity:
1/15/2024:
-------------------------------------------------
"""
import abc

from projects.monitoring.common.do.alarm import Alarm


class AlarmFormat(abc.ABC):
    def __init__(self, subscribe_alarm_info, time_format="%Y-%m-%d %H:%M:%S"):
        self.subscribe_alarm_info = subscribe_alarm_info
        self.time_format = time_format
        assert isinstance(self.subscribe_alarm_info, (list, dict))

    def __call__(self):
        format_alarm_mapping = {}
        for alarm in self.subscribe_alarm_info:
            if isinstance(self.subscribe_alarm_info, dict):
                alarm = self.subscribe_alarm_info[alarm]
            format_alarm = self._format_alarm(alarm)
            format_alarm_mapping[format_alarm.alarm_id] = format_alarm
        return format_alarm_mapping

    @abc.abstractmethod
    def _format_alarm(self, alarm) -> Alarm:
        """
        This function formats the zabbix alarm.
        Args:
            alarm:

        Returns:

        """
        pass
